const express = require("express");
const logger = require("morgan");

const myapp = express(); //启动服务
myapp.use(logger("dev")) //配置日志
myapp.use(express.static(__dirname + "/src")) //配置静态资源路径


//拦截（get请求方法）/login.do请求（直接在app.js文件中拦截）
myapp.get("/login.do", function(req,res) {
        var user = [
            {username:"datou",pwd:"234"},
            {username:"mahu",pwd:"123"}
        ]
        let userName = req.query.userName;
        let pwd = req.query.pwd;
        console.log(userName,pwd);

        //通过服务器登录
        for (var i = 0; i < user.length; i++) {
            if (user[i].username == userName && user[i].pwd == pwd) {
                return res.send("登录成功") //一个请求只能send一次
            }
        }
        res.send("登录失败") //写在for循环外面

})

myapp.listen(5000, () => { //端口
    console.log("express服务器启动")
})
  